import pandas as pd
import math


def get_distance(long1, lat1, long2, lat2):
    R = 6378137  # 地球半径
    lat1 = lat1 * math.pi / 180.0
    lat2 = lat2 * math.pi / 180.0
    a = lat1 - lat2
    b = (long1 - long2) * math.pi / 180.0
    sa2 = math.sin(a / 2.0)
    sb2 = math.sin(b / 2.0)
    d = 2 * R * math.asin(math.sqrt(sa2 * sa2 + math.cos(lat1) * math.cos(lat2) * sb2 * sb2))

    return d


if __name__ == '__main__':
    path = './station/4g_base_station.txt'
    df = pd.read_csv(path, header=None, sep='\s+')
    # print(df)
    print(len(df))
    dict = {}

    print(df[1][0])
    print(df[2][0])
    for i in range(len(df)):
        # print(i)
        list = []
        list.append(df[1][i])
        list.append(df[2][i])
        dict[i+1] = list
    print(dict)

    lo1 = dict[1][0]
    la1 = dict[1][1]
    lo2 = dict[2][0]
    la2 = dict[2][1]
    distance = get_distance(lo1,la1,lo2,la2)
    print(distance)